package com.wxmit.module.system.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.wxmit.base.util.StringUtils;
import com.wxmit.module.system.domain.SysUser;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * sysUser excel 导入时 部门 name 2 id 的转换类
 *
 * @author huangxiong
 * @version V1.0
 * @date 2023/1/9 14:48
 */
public class ExcelSysUserDeptReadListener implements ReadListener<SysUser> {

    /**
     *  key: name
     *  value : id
     */
    private final Map<String,Long> deptNameMap;

    public ExcelSysUserDeptReadListener(Map<String,Long> deptNameMap){
        this.deptNameMap = deptNameMap;
    }

    @Override
    public void invoke(SysUser data, AnalysisContext context) {
        if(StringUtils.isNotEmpty(data.getDeptName())){
            Long id = deptNameMap.get(data.getDeptName());
            data.setDeptId(id);
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {}
}
